import time
import threading
from . import wm, db, app, utils
from .models import bank_logger

class UnLocker(threading.Thread):
    """docstring for UnLocker"""
    def __init__(self):
        super(UnLocker, self).__init__()
        self.start()
    def run(self):
        i = 0
        while app.config.get("RUNNING",True):
            i += 1
            if i % 10 != 0:
                time.sleep(1)
            else:
                not_commit_bank_list = bank_logger.query.filter(bank_logger.start_time < utils.create_time_nmin_before() ,bank_logger.is_finish != 1 ,bank_logger.is_lock != 0).all()
                for bank_obj in not_commit_bank_list:
                    wm.unlockTicket(bank_obj.wid)
                    bank_obj.is_lock = 0
                    db.session.save(bank_obj)
        